define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'factor/authority/index' + location.search,
                    add_url: 'factor/authority/add',
                    edit_url: 'factor/authority/edit',
                    del_url: 'factor/authority/del',
                    multi_url: 'factor/authority/multi',
                    import_url: 'factor/authority/import',
                    table: 'carbon_factor_authority',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), searchable: false},
                        {
                            field: 'report_sn',
                            title: __('Report_sn'),
                            searchable: false,
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'product_name',
                            title: __('Product_name'),
                            operate: 'LIKE',
                            table: table,
                            class: 'autocontent',
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'product_specification',
                            title: __('Product_specification'),
                            searchable: false,
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'product_function',
                            title: __('Product_function'),
                            searchable: false,
                            formatter: Table.api.formatter.content
                        },
                        {
                            field: 'quantification_method',
                            title: __('Quantification_method'),
                            searchList: Config.qMethodList,
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'factor_name', title: __('Factor_id'), searchable: false},
                        {field: 'user_name', title: __('User_id'), searchable: false},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {'0': '待审', '1': '已通过', '2': '驳回'},
                            formatter: Table.api.formatter.status
                        },
                        {field: 'reason', title: __('Reason'), searchable: false},
                        {
                            field: 'checktime',
                            title: __('Checktime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [{
                                name: 'detail',
                                text: '认证数据',
                                icon: 'fa fa-list',
                                extend: 'data-area=["70%","60%"]',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'factor/account_authentication/detail'
                            }, {
                                name: 'edit',
                                text: '审核',
                                icon: 'fa fa-check-square-o',
                                extend:'data-area=["70%","60%"]',
                                classname: 'btn btn-success btn-xs btn-detail btn-dialog',
                                url: 'factor/authority/edit?ids={ids}'
                            },{
                                name: 'del',
                                hidden: true,
                                disable: true,
                            }],
                            formatter: Table.api.formatter.operate
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            // 禁用上传按钮
            $('.faupload').hide();
            $('.fachoose').hide();
            Controller.api.bindevent();
            $('.btn-trash').hide();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
